home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / Drivers / Load PCI Driver / MoreFiles / IterateDirectory.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  6.4 KB  |  176 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        IterateDirectory.h
  3.     
  4.     Description:File Manager directory iterator routines.
  5.  
  6.     Author:        JL
  7.  
  8.     Copyright:     Copyright: © 1995-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/25/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23. #ifndef __ITERATEDIRECTORY__
  24. #define __ITERATEDIRECTORY__
  25.  
  26. #include <Types.h>
  27. #include <Files.h>
  28.  
  29. #include "Optimization.h"
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. /*****************************************************************************/
  36.  
  37. typedef    pascal    void (*IterateFilterProcPtr) (const CInfoPBRec * const cpbPtr,
  38.                                               Boolean *quitFlag,
  39.                                               void *yourDataPtr);
  40. /*    ¶ Prototype for the IterateFilterProc function IterateDirectory calls.
  41.     This is the prototype for the IterateFilterProc function which is
  42.     called once for each file and directory found by IterateDirectory. The
  43.     IterateFilterProc gets a pointer to the CInfoPBRec that IterateDirectory
  44.     used to call PBGetCatInfo. The IterateFilterProc can use the read-only
  45.     data in the CInfoPBRec for whatever it wants.
  46.     
  47.     If the IterateFilterProc wants to stop IterateDirectory, it can set
  48.     quitFlag to true (quitFlag will be passed to the IterateFilterProc
  49.     false).
  50.     
  51.     The yourDataPtr parameter can point to whatever data structure you might
  52.     want to access from within the IterateFilterProc.
  53.  
  54.     cpbPtr        input:    A pointer to the CInfoPBRec that IterateDirectory
  55.                         used to call PBGetCatInfo. The CInfoPBRec and the
  56.                         data it points to must not be changed by your
  57.                         IterateFilterProc.
  58.     quitFlag    output:    Your IterateFilterProc can set quitFlag to true
  59.                         if it wants to stop IterateDirectory.
  60.     yourDataPtr    input:    A pointer to whatever data structure you might
  61.                         want to access from within the IterateFilterProc.
  62.     
  63.     __________
  64.     
  65.     Also see:    IterateDirectory, FSpIterateDirectory
  66. */
  67.  
  68. #define CallIterateFilterProc(userRoutine, cpbPtr, quitFlag, yourDataPtr) \
  69.         (*(userRoutine))((cpbPtr), (quitFlag), (yourDataPtr))
  70.  
  71. /*****************************************************************************/
  72.  
  73. pascal    OSErr    IterateDirectory(short vRefNum,
  74.                                  long dirID,
  75.                                  ConstStr255Param name,
  76.                                  unsigned short maxLevels,
  77.                                  IterateFilterProcPtr iterateFilter,
  78.                                  void *yourDataPtr);
  79. /*    ¶ Iterate (scan) through a directory's content.
  80.     The IterateDirectory function performs a recursive iteration (scan) of
  81.     the specified directory and calls your IterateFilterProc function once
  82.     for each file and directory found.
  83.     
  84.     The maxLevels parameter lets you control how deep the recursion goes.
  85.     If maxLevels is 1, IterateDirectory only scans the specified directory;
  86.     if maxLevels is 2, IterateDirectory scans the specified directory and
  87.     one subdirectory below the specified directory; etc. Set maxLevels to
  88.     zero to scan all levels.
  89.     
  90.     The yourDataPtr parameter can point to whatever data structure you might
  91.     want to access from within the IterateFilterProc.
  92.  
  93.     vRefNum            input:    Volume specification.
  94.     dirID            input:    Directory ID.
  95.     name            input:    Pointer to object name, or nil when dirID
  96.                             specifies a directory that's the object.
  97.     maxLevels        input:    Maximum number of directory levels to scan or
  98.                             zero to scan all directory levels.
  99.     iterateFilter    input:    A pointer to the routine you want called once
  100.                             for each file and directory found by
  101.                             IterateDirectory.
  102.     yourDataPtr        input:    A pointer to whatever data structure you might
  103.                             want to access from within the IterateFilterProc.
  104.     
  105.     Result Codes
  106.         noErr                0        No error
  107.         nsvErr                -35        No such volume
  108.         ioErr                -36        I/O error
  109.         bdNamErr            -37        Bad filename
  110.         fnfErr                -43        File not found
  111.         paramErr            -50        No default volume or iterateFilter was NULL
  112.         dirNFErr            -120    Directory not found or incomplete pathname
  113.                                     or a file was passed instead of a directory
  114.         afpAccessDenied        -5000    User does not have the correct access
  115.         afpObjectTypeErr    -5025    Directory not found or incomplete pathname
  116.         
  117.     __________
  118.     
  119.     See also:    IterateFilterProcPtr, FSpIterateDirectory
  120. */
  121.  
  122. /*****************************************************************************/
  123.  
  124. pascal    OSErr    FSpIterateDirectory(const FSSpec *spec,
  125.                                     unsigned short maxLevels,
  126.                                     IterateFilterProcPtr iterateFilter,
  127.                                     void *yourDataPtr);
  128. /*    ¶ Iterate (scan) through a directory's content.
  129.     The FSpIterateDirectory function performs a recursive iteration (scan)
  130.     of the specified directory and calls your IterateFilterProc function once
  131.     for each file and directory found.
  132.     
  133.     The maxLevels parameter lets you control how deep the recursion goes.
  134.     If maxLevels is 1, FSpIterateDirectory only scans the specified directory;
  135.     if maxLevels is 2, FSpIterateDirectory scans the specified directory and
  136.     one subdirectory below the specified directory; etc. Set maxLevels to
  137.     zero to scan all levels.
  138.     
  139.     The yourDataPtr parameter can point to whatever data structure you might
  140.     want to access from within the IterateFilterProc.
  141.  
  142.     spec            input:    An FSSpec record specifying the directory to scan.
  143.     maxLevels        input:    Maximum number of directory levels to scan or
  144.                             zero to scan all directory levels.
  145.     iterateFilter    input:    A pointer to the routine you want called once
  146.                             for each file and directory found by
  147.                             FSpIterateDirectory.
  148.     yourDataPtr        input:    A pointer to whatever data structure you might
  149.                             want to access from within the IterateFilterProc.
  150.     
  151.     Result Codes
  152.         noErr                0        No error
  153.         nsvErr                -35        No such volume
  154.         ioErr                -36        I/O error
  155.         bdNamErr            -37        Bad filename
  156.         fnfErr                -43        File not found
  157.         paramErr            -50        No default volume or iterateFilter was NULL
  158.         dirNFErr            -120    Directory not found or incomplete pathname
  159.         afpAccessDenied        -5000    User does not have the correct access
  160.         afpObjectTypeErr    -5025    Directory not found or incomplete pathname
  161.         
  162.     __________
  163.     
  164.     See also:    IterateFilterProcPtr, IterateDirectory
  165. */
  166.  
  167. /*****************************************************************************/
  168.  
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172.  
  173. #include "OptimizationEnd.h"
  174.  
  175. #endif    /* __ITERATEDIRECTORY__ */
  176.